<template>
  <transition
      @enter="enter"
      @leave="leave"
      :css="false"
  >
    <div class="mini-player" v-show="this.isMiniPlayer">
      <div class="player-wrapper">
        <div class="player-left" @click.stop="showNormalPlayer">
          <img :src="currentSong.picUrl" ref="miniCd">
          <div class="player-title">
            <h3>{{ currentSong.name }}</h3>
            <p>{{ currentSong.singer }}</p>
          </div>
        </div>
        <div class="player-right">
          <div class="play" ref="play" @click.stop="play"></div>
          <div class="next" ref="next" @click.stop="next"></div>
          <div class="list" @click.stop="showList"></div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import {mapActions, mapGetters} from "vuex"
import Velocity from "velocity-animate";
import 'velocity-animate/velocity.ui'

export default {
  name: "MiniPlayer",
  methods: {
    ...mapActions([
      'setFullScreen',
      'setMiniPlayer',
      'setListPlayer',
      'setIsPlaying',
      'setCurrentIndex'
    ]),
    showList() {
      //调用父组件的 showList
      // this.$emit("showList")
      this.setListPlayer(true)
    },
    showNormalPlayer() {
      this.setFullScreen(true);
      this.setMiniPlayer(false);
    },
    enter(el, done) {
      Velocity(el, 'transition.bounceUpIn', {duration: 300}, () => done())
    },
    leave(el, done) {
      Velocity(el, 'transition.bounceDownOut', {duration: 300}, () => done())
    },
    play() {
      this.setIsPlaying(!this.isPlaying)
    },
    next(){
      this.setCurrentIndex(this.currentIndex + 1)
    }
  },
  computed: {
    ...mapGetters([
      "isMiniPlayer",
      'isPlaying',
      'currentSong',
      'currentIndex'
    ])
  },
  watch: {
    isPlaying(newValue, oldValue) {
      if (newValue) {
        this.$refs.play.classList.add('active')
        this.$refs.miniCd.classList.add('active')
      } else {
        this.$refs.play.classList.remove('active')
        this.$refs.miniCd.classList.remove('active')
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import "../../assets/css/mixin";
@import "../../assets/css/variable";

.mini-player {
  width: 100%;
  height: 100px;
  @include bg_color();
  position: fixed;
  bottom: 0;
  left: 0;
  border-top: 1px solid #ccc;

  .player-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .player-left {
      display: flex;
      align-items: center;
      justify-content: left;
      flex: 1;
      margin-right: 20px;
      @include no-wrap();
      img {
        width: 80px;
        height: 80px;
        border-radius: 50%;
        border: 1px solid #000000;
        margin: 0 20px;
        animation: sport 40s linear infinite;
        animation-play-state: paused;
        &.active {
          animation-play-state: running;
        }
      }

      h3 {
        color: #ffffff;
        @include font_size($font-medium);
        @include no-wrap();
      }

      p {
        color: #f1f1f1;
        @include font_size($font-medium_s);
      }

    }
    .player-right {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 32%;
      .play {
        width: 60px;
        height: 60px;
        @include bg_img("../../assets/images/play");
        &.active {
          @include bg_img("../../assets/images/pause");

        }
      }
      .next{
        width: 60px;
        height: 60px;
        @include bg_img("../../assets/images/next");
        margin-left: 20px;
      }
      .list {
        width: 100px;
        height: 100px;
        @include bg_img("../../assets/images/list");
      }
    }
  }
}

@keyframes sport {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>
